﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports NHibernate
Imports SIAVU.Dominio

Namespace Persistencia

    Public Class PlazoPersistencia

        Public Function GetByMesAnio(ByVal oPlazo As Plazo) As Plazo
            Dim session As ISession = NHibernateHelper.OpenSession()
            Try
                Dim oPlazos As IList(Of Plazo)

                oPlazos = session.CreateCriteria(GetType(Plazo)).Add(Criterion.Expression.Eq("Mes", oPlazo.Mes)).Add(Criterion.Expression.Eq("Anio", oPlazo.Anio)).List(Of Plazo)()
                If oPlazos.Count > 0 Then
                    Return oPlazos(0)
                Else
                    Return Nothing
                End If

            Catch ex As Exception
                Throw

            Finally
                session.Close()
            End Try
        End Function

        'Public Function GetByMesAnio(ByVal oPlazo As Plazo, ByRef Session As ISession) As Plazo
        '    Try
        '        Dim oPlazos As IList(Of Plazo)

        '        oPlazos = Session.CreateCriteria(GetType(Plazo)).Add(Criterion.Expression.Eq("Mes", oPlazo.Mes)).Add(Criterion.Expression.Eq("Anio", oPlazo.Anio)).List(Of Plazo)()
        '        If oPlazos.Count > 0 Then
        '            Return oPlazos(0)
        '        Else
        '            Return Nothing
        '        End If

        '    Catch ex As Exception
        '        Throw

        '    End Try
        'End Function

        Public Sub guardar(ByVal oPlazo As Plazo)
            Dim session As ISession = NHibernateHelper.OpenSession()
            Dim oTransaccion As ITransaction = Nothing
            Try
                oTransaccion = session.BeginTransaction()
                oTransaccion.Begin()

                session.SaveOrUpdate(oPlazo)
                oTransaccion.Commit()

            Catch ex As Exception
                oTransaccion.Rollback()
                Throw

            Finally
                session.Close()
            End Try
        End Sub

    End Class

End Namespace

